#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int n = timeSeries.size();
        int sum = 0;
        for (int i = 0; i < n; i++) {

            if (i + 1 < n && timeSeries[i] + duration - 1 >= timeSeries[i + 1]) sum += timeSeries[i + 1] - timeSeries[i];
            else  sum += duration;

        }
        return sum;
    }
};